/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package avenue;

import java.awt.Color;
import java.awt.Component;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;
import model.VehicleColour;

/**
 *
 * @author Aggelos
 */
public class ColourRenderer extends DefaultListCellRenderer {

    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
   
        if (value instanceof VehicleColour) {
            VehicleColour mec = (VehicleColour) value;
            setText(mec.getName());

            if (!isSelected) {
                setBackground(Color.decode(mec.getColorCode()));
                setForeground(Color.black);
            } else if (!cellHasFocus){
                setBackground(Color.BLUE);
                setForeground(Color.decode(mec.getColorCode()));
            } else{
                setBackground(Color.decode(mec.getColorCode()));
                setForeground(Color.black);
            }
        }
         return this;
    }
}
       